updating oE process_lines
process_lines
include io.e namespace io public function process_lines(object file, integer proc, object user_data = 0)
processes the contents of a file, one line at a time.
Parameters:
- file : an object. Either a file path or the handle to an open file. An empty string signifies STDIN -- the console keyboard.
- proc : an integer. The routine_id of a function that will process the line.
- user_data : on object. This is passed untouched to proc for each line.
Returns:
An object. If 0 then all the file was processed successfully. Anything else means that something went wrong and this is whatever value was returned by proc.
Comments:
- The function proc must accept three parameters:
- A sequence: The line to process. It will not contain an end-of-line character.
- An integer: The line number.
- An object : This is the user_data that was passed to process_lines.
- If file was a sequence, the file will be closed on completion. Otherwise, it will remain open, and be positioned where ever reading stopped.
Example 1:
-- Format each supplied line according to the format pattern supplied as well. function show(sequence aLine, integer line_no, object data) writefln( data[1], {line_no, aLine}) if data[2] > 0 and line_no = data[2] then return 1 else return 0 end if end function -- Show the first 20 lines. process_lines("sample.txt", routine_id("show"), {"[1z:4] : [2]", 20})
See Also:
Not Categorized, Please Help
|